﻿using DoNet.ORM.Repository.EFCore;
using DoNet.ORM.Repository.NHiberbate;
using DoNet.ORM.Repository.Repository;

namespace DoNet.ORM.Repository
{
    public static class RepositoryFactory
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="ormType">ORM</param>
        /// <param name="dataBaseType">数据库类型</param>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static IRepository Create(OrmType ormType, DataBaseType dataBaseType, string connectionString)
        {
            switch (ormType)
            {
                case OrmType.Dapper:
                    return new DapperRepository(dataBaseType, connectionString);
                case OrmType.SqlSugar:
                    return new SqlSugarRepository(dataBaseType, connectionString);

                case OrmType.EFCore:
                    return new EFCoreRepository(new MyDbContext(dataBaseType, connectionString));
                case OrmType.NHiberbate:
                    return new NHibernateRepository(new SessionFactoryHelper(dataBaseType, connectionString));
                default:
                    throw new ArgumentException("不支持的 ORM 类型");
            }
        }
    }
}
